def matrix(n, m):
    mat = []
    for i in range(n):
        a = list(map(int, input().split()))
        mat.append(a)
    # 构建一个n行，m列的二维list
    ans = [[0] * m for i in range(n)]

    for i in range(n):
        for j in range(m):
            tot, cnt = 0, 0  # 表示总和，个数
            # 遍历周围的3*3区域
            for delta_x in [-1, 0, 1]:
                for delta_y in [-1, 0, 1]:
                    x = i + delta_x
                    y = j + delta_y
                    # 判断坐标是否存在
                    if 0 <= x < n and 0 <= y < m:
                        tot += mat[x][y]
                        cnt += 1
            ans[i][j] = tot // cnt
    return ans

n, m = map(int, input().split())
ma = matrix(n, m)

for a in ma:
    print(" ".join(map(str, a)))